package com.cxx.home.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cxx.common.ReadView;
import com.cxx.common.WriteView;
import com.cxx.home.dto.travel.TravelRecordDto;
import com.cxx.home.dto.travel.TravelSpotDto;
import com.cxx.home.dto.travel.TravelStatsDto;
import com.cxx.home.dto.travel.TravelSummaryDto;
import com.cxx.home.service.TravelService;
import com.cxx.home.vo.TravelQueryVo;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/travel")
@Tag(name = "旅行记录")
public class TravelController {
    @Resource
    private TravelService travelService;

    @Operation(summary = "新增旅行景点")
    @PostMapping("/spot")
    public Boolean addTravelSpot(@RequestBody @JsonView(WriteView.class) @Validated TravelSpotDto travelSpotDto) {
        return travelService.addTravelSpot(travelSpotDto);
    }

    @Operation(summary = "更新旅行景点")
    @PutMapping("/spot/{id}")
    public Boolean updateTravelSpot(@PathVariable("id") long id,
                                    @RequestBody @JsonView(WriteView.class) TravelSpotDto travelSpotDto) {
        return travelService.updateTravelSpot(id, travelSpotDto);
    }

    @Operation(summary = "删除旅行景点")
    @DeleteMapping("/spot/{id}")
    public Boolean deleteTravelSpot(@PathVariable("id") long id) {
        return travelService.deleteTravelRecord(id);
    }

    @Operation(summary = "分页查询旅行景点")
    @GetMapping("/spot/page")
    public IPage<TravelSummaryDto> queryTravelSummary(@RequestParam("currentPage") Integer currentPage,
                                                      @RequestParam("pageSize") Integer pageSize,
                                                      TravelQueryVo travelQueryVo) {
        return travelService.queryTravelSummary(currentPage, pageSize, travelQueryVo);
    }

    @Operation(summary = "查询旅行景点")
    @GetMapping("/spot/{id}")
    public @JsonView(ReadView.class) TravelSpotDto queryTravelSpot(@PathVariable("id") long id) {
        return travelService.queryTravelSpot(id);
    }

    @Operation(summary = "查询所有旅行景点")
    @GetMapping("/spot/name")
    public List<String> queryFoodName() {
        return travelService.queryTravelSpotName();
    }

    @Operation(summary = "新增旅行记录")
    @PostMapping("/record")
    public Boolean addTravelRecord(@RequestBody @JsonView(WriteView.class) @Validated TravelRecordDto travelRecordDto) {
        return travelService.addTravelRecord(travelRecordDto);
    }

    @Operation(summary = "更新旅行记录")
    @PutMapping("/record/{id}")
    public Boolean updateTravelRecord(@PathVariable("id") long id,
                                      @RequestBody @JsonView(WriteView.class) TravelRecordDto travelRecordDto) {
        return travelService.updateTravelRecord(id, travelRecordDto);
    }

    @Operation(summary = "删除旅行记录")
    @DeleteMapping("/record/{id}")
    public Boolean deleteTravelRecord(@PathVariable("id") long id) {
        return travelService.deleteTravelRecord(id);
    }

    @Operation(summary = "查询旅行记录")
    @GetMapping("/record")
    public @JsonView(ReadView.class) List<TravelRecordDto> queryTravelRecord(@RequestParam("startDate") String startDate,
                                                                             @RequestParam("endDate") String endDate) {
        return travelService.queryTravelRecord(startDate, endDate);
    }

    @Operation(summary = "查询旅行类别")
    @GetMapping("/category")
    public List<String> queryTravelCategory() {
        return travelService.queryTravelCategory();
    }

    @Operation(summary = "查询旅行统计")
    @GetMapping("/stats")
    public TravelStatsDto queryTravelStats() {
        return travelService.queryTravelStats();
    }
}
    